package com.lzj.demo.design.chain.fzw;

import cn.hutool.core.date.DateUtil;
import com.lzj.demo.design.chain.fzw.chain.AuthService;

import java.text.ParseException;
import java.util.Date;
import java.util.Objects;

public class AuthController {
    public AuthInfo doAuth(String uId, String orderId, Date authDate) throws ParseException {
        //三级审批
        Date date = AuthService.queryAuthInfo(uId,orderId);
        if(Objects.isNull(date)){
            return new AuthInfo("001","单号: ",orderId," 状态:待三级负责人审批 ","李工");
        }
        //二级审批
        if(getLevel_2(authDate)){
            date = AuthService.queryAuthInfo("1002",orderId);
            if(Objects.isNull(date)){
                return new AuthInfo("001","单号: ",orderId," 状态:待二级负责人审批 ","钱经理");
            }
        }
        //一级审批
        if(getLevel_1(authDate)){
            date = AuthService.queryAuthInfo("1003",orderId);
            if(Objects.isNull(date)){
                return new AuthInfo("001",orderId," 状态:待一级负责人审批 ","赵总");
            }
        }
        return new AuthInfo("001","单号: ",orderId," 状态:审批 完成","系统");
    }

    /**
     * 二级审批
     * */
    private boolean getLevel_2(Date authDate){
        return authDate.after(DateUtil.parse("2020-06-01 00:00:00","yyyy-MM-dd HH:mm:ss"))
                && authDate.before(DateUtil.parse("2020-06-25 23:59:59","yyyy-MM-dd HH:mm:ss"));
    }
    /**
     * 一级审批
     * */
    private boolean getLevel_1(Date authDate){
        return authDate.after(DateUtil.parse("2020-06-11 00:00:00","yyyy-MM-dd HH:mm:ss"))
                && authDate.before(DateUtil.parse("2020-06-20 23:59:59","yyyy-MM-dd HH:mm:ss"));
    }
}
